package Easy移动零;

public class Solution {
    public void moveZeroes(int[] nums) {
        for (int i = 0,j = 1; i < nums.length && j< nums.length; ) {
            if (nums[i] == 0 && nums[j]!=0){
                nums[i] = nums[j];
                nums[j] = 0;
                i++;
                j++;
            }
            else{
                j++;
            }
            if (nums[i]!=0)
                i++;
        }
    }

    //速度版
    public void moveZeroes1(int[] nums) {
        if (nums == null || nums.length <= 1) {
            return;
        }
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[index] = nums[i];
                index++;
            }
        }

        for (int i = index; i < nums.length; i++) {
            nums[i] = 0;
        }
    }
}
